package com.foundryx.shared.exception.i18n;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * @className: I18nMessageUtil
 * @author: ocxz1
 * @date: 2025/6/20 上午11:14
 * @Version: 1.0
 * @description: fx-share-resources
 */
public class I18nMessageUtil {

    /**
     * 获取国际化信息
     * @param baseName 基础名称
     * @param messageCode 信息码
     * @param locale 地区
     * @return
     */
    public static String getMessage(String baseName, String messageCode, Locale locale) {
        if (messageCode == null) {
            return null;
        }

        if (locale == null) {
            locale = Locale.getDefault();
        }

        try {
            return ResourceBundle.getBundle(baseName, locale).getString(messageCode);
        } catch (Exception e) {
            return messageCode; // 如果找不到，返回原始 code
        }
    }
}
